/* eslint-disable no-param-reassign */
import lodash from 'lodash'
const initData = {
  name: '', // 任务名称
  startTimeStr: '',
  endTimeStr: '',
  type: '2', // 是否自动升级
  forceUpgrade: '', // 是否强制升级
  silenceUpgrade: '', // 是否静默升级
  recordNo: '', // 备案号
  remark: '',
  satisfyType: 1 // 熔断保障 满足所有or满足任何
}
const comonData = {
  channel: 1,//通道 0：工程院通道 1：规划院通道
  projectId: '',
  projectName: '',
  strategyId: undefined,
  strategyName: '',
  modelId: '', // 策略对应的车型id
  factoryChannel: undefined, // 唤醒通道
  choseType: 1, // 选择车辆的方式 批量选择or来自文件
  isSlefSelect: false, // 是否自定义
  selectCarTotal: 0, // 自定义车辆数
  pretreatmentId: '', // 文件预处理id
  fileFailCar: 0,
  fileSuccessCar: 0,
  fileTotal: 0
}
//任务附件项 配置
const taskFileConfig = [
  {
    name : '供应商测试报告',
    key: 'supplierTestReport',
    boolKey: 'uploadSupplierTestReport',
    reasonKey: 'noSupplierReportReason'
  },
  {
    name : '释放单',
    key: 'releaseBill',
    boolKey: 'uploadReleaseBill',
    reasonKey: 'noReleaseBillReason'
  },
  {
    name : '产品测试报告',
    key: 'productTestReport',
    boolKey: 'uploadProductTestReport',
    reasonKey: 'noProductReportReason'
  },
  //@update 23-06-15 by chen.jinfan 对接工程院发起时不用传，审批时上传
  // {
  //   name : 'OTA通道测试报告',
  //   key: 'channelTestReport',
  //   boolKey: 'uploadChannelReport',
  //   reasonKey: 'noChannelReportReason'
  // },
  // {
  //   name : 'OTA功能测试报告',
  //   key: 'functionTestReport',
  //   boolKey: 'uploadFunctionTestReport',
  //   reasonKey: 'noFunctionReportReason'
  // },
  // {
  //   name : '测试部门验证报告',
  //   key: 'testDeptVerifyReport',
  //   boolKey: 'upTestDeptVerifyReport',
  //   reasonKey: 'noTestVerifyReportReason'
  // },
]
let taskGcyExt;
//重置数据，深拷贝，解决浅拷贝数组无法清空问题
function initTaskGcyExt() {
  taskGcyExt = {
    batchName: '',
    upgradeAccessProve: [],
    applyUserId: undefined,
    updateScope: [],
    supplierVerifyConclusion: undefined,
    productVerifyConclusion: undefined
  };
  taskFileConfig.forEach(cfg => {
    taskGcyExt[cfg.key] = [];
    taskGcyExt[cfg.boolKey] = true;
    taskGcyExt[cfg.reasonKey] = '';
  })
}
initTaskGcyExt();

let newTaskData = {
  ...comonData,
  ...initData,
  startTime: null,
  endTime: null,
  strategyId:null,
  strategyName:null,
  modelId:null,
  // 第二步车辆筛选
  queryParam: {},
  selectCarIds: [], // 自定义勾选的车辆
  file: {},
  climbControlList: [], // 爬坡计划列表
  turnOnAudit: true,
  templateId: '', // 模板id
  templateVersionSeqNo: '',
  processList: [], // 任务审核
  turnOnGrayscale: true,
  grayscaleList: [
    { level: 1, pushNumPercent: '', installNumPercent: '', conditionType: 1 },
    { level: 2, pushNumPercent: '', installNumPercent: '', conditionType: 1 }
  ],
  taskGcyExt: {...taskGcyExt}
};
const newTask = {
  state: {
    stepNum: 0,
    // 存放当前步的前一次操作在哪一步,如果是-1则无前一次操作，例如添加进来的
    prevStepNum: -1,
    taskFileConfig,
    newTaskData: {
      warehouse: {...lodash.cloneDeep(newTaskData),duration: 30,copyId:undefined},
      AUTO: {...lodash.cloneDeep(newTaskData), type: '2'},
      queryParam: {},
    },
    detailAddCar: {
      ...comonData,
      // 第二步车辆筛选
      queryParam: {},
      selectCarIds: [], // 自定义勾选的车辆
      file: {}
    }
  },
  mutations: {
    RESET_NEWTASK_DATA (state, type) {
      state.stepNum = 0
      state.prevStepNum = -1
      state.newTaskData[type] = Object.assign(state.newTaskData[type], {
        ...comonData, ...initData,
        type: state.newTaskData[type].type
      });
      state.newTaskData[type].strategyId = undefined
      state.newTaskData[type].startTime = null
      state.newTaskData[type].endTime = null
      state.newTaskData[type].queryParam = {}
      state.newTaskData[type].selectCarIds = []
      state.newTaskData[type].file = {}
      state.newTaskData[type].climbControlList = []
      state.newTaskData[type].turnOnAudit = true
      state.newTaskData[type].templateId = ''
      state.newTaskData[type].processList = []
      state.newTaskData[type].turnOnGrayscale = true
      state.newTaskData[type].grayscaleList = [
        { level: 1, pushNumPercent: '', installNumPercent: '', conditionType: 1 },
        { level: 2, pushNumPercent: '', installNumPercent: '', conditionType: 1 }
      ]
      initTaskGcyExt();
      Object.assign(state.newTaskData[type].taskGcyExt, taskGcyExt);
    },
    RESET_ADDCAR (state) {
      state.detailAddCar = Object.assign(state.detailAddCar, { ...comonData })
      state.detailAddCar.queryParam = {}
      state.detailAddCar.selectCarIds = []
      state.detailAddCar.file = {}
    },
    SET_STEPNUM: (state, stepNum) => {
      state.stepNum = stepNum
    },
    SET_PREV_STEPNUM: (state, stepNum) => {
      state.prevStepNum = stepNum
    },
  },
  actions: {

  }
}

export default newTask
